#delimit;
set logtype text;
log using gallup.out,
replace; 
set more off;

/* original data input statement from Gallup data 

infix wtfctr 7-10 d1 66 d2 67-68 d4 71 d5a 72 d5b 73 d5c 74-75 d5d 76-77
d9 87 d9a 88 d10 89 d14 97-98 q2 120 q19 163 q20 164 q24 172 q26 174
using g200811.dat; */

/* read subset gallup data */

insheet using gallup.csv, comma; 

/* create various party id variables */

gen partyid3=2 if d9==1;
replace partyid3=0 if d9==2;
replace partyid3=1 if d9==3;

gen rep=(d9==1) if d9<4;
gen dem=(d9==2) if d9<4;
gen ind=(d9==3) if d9<4;

gen partyid5=0 if d9==2;
replace partyid5=4 if d9==1;
replace partyid5=2 if d9==3 & d9a==3;
replace partyid5=2 if d9==3 & d9a==4;
replace partyid5=1 if d9==3 & d9a==1;
replace partyid5=3 if d9==3 & d9a==2;

gen ideology=5-d10 if d10<6;

/* create demographic variables */

gen female=(d1==2);
gen age=d2 if d2>0;
gen hispanic=(d4==1);
gen white=(d5a==1);
gen black=(d5b==1);
replace hispanic=1 if d5c==20 | d5d==20;
gen income=d14 if d14>0 & d14<12;

/* create bush approval */

gen bushappr=(q2==1) if q2<3;

/* create bush credibility variable */

gen bushcred=(q24==2) if q24<3;

/* create timetable variable */

gen disapptime=2 if q19==1;
replace disapptime=1 if q20==2;
replace disapptime=0 if q20==1;

/* create iraq success variable */

gen iraqwin=4-q26 if q26>=1 & q26<=4;

/* Table 4 */
/* Table 4A */
tab bushcred partyid3 if bushappr==0 [iweight=wtfctr], col;
tab bushcred partyid3 if bushappr==1 [iweight=wtfctr], col;

/* Table 4B */

tab iraqwin partyid3 if bushappr==0 [iweight=wtfctr], col;
tab iraqwin partyid3 if bushappr==1 [iweight=wtfctr], col;

/* Table 4C */

tab disapptime partyid3 if bushappr==0 [iweight=wtfctr], col;
tab disapptime partyid3 if bushappr==1 [iweight=wtfctr], col;

/* Table A2 */

tab iraqwin partyid5 [iweight=wtfctr], col;

/* Table A3 */

tab disapptime partyid5 [iweight=wtfctr], col;

/* Table A4 */

tab bushcred partyid5 [iweight=wtfctr], col;

/* Table A5 */

tab bushappr partyid5 [iweight=wtfctr], col;

/* Table A8 */

tab iraqwin bushcred [iweight=wtfctr] if partyid5==3 | partyid5==4, row;
tab disapptime bushcred [iweight=wtfctr] if partyid5==3 | partyid5==4, row;

/* Table A9 */

tab iraqwin bushcred [iweight=wtfctr] if partyid5==2, row;
tab disapptime bushcred [iweight=wtfctr] if partyid5==2, row;

/* Table A10 */

tab iraqwin bushcred [iweight=wtfctr] if partyid5==0 | partyid5==1, row;
tab disapptime bushcred [iweight=wtfctr] if partyid5==0 | partyid5==1, row;

/* Table A11 */

tab bushcred bushappr [iweight=wtfctr], col;

/* Table A12 */

logit bushcred bushappr iraqwin disapptime dem rep ideology
[pweight=wtfctr];  
logit bushcred bushappr iraqwin disapptime dem rep ideology female age
black hispanic income [pweight=wtfctr]; 

/* Table A13 */

logit bushcred bushappr iraqwin disapptime ideology
female age black hispanic income [pweight=wtfctr] if dem==1;  
logit bushcred bushappr iraqwin disapptime ideology
female age black hispanic income [pweight=wtfctr] if ind==1;  
logit bushcred bushappr iraqwin disapptime ideology
female age black hispanic income [pweight=wtfctr] if rep==1;  

/* Table A14 */

tab iraqwin bushappr [iweight=wtfctr], col;
tab disapptime bushappr [iweight=wtfctr], col;

/* Table A15 */

tab iraqwin bushappr [iweight=wtfctr] if partyid3==2, col;
tab disapptime bushappr [iweight=wtfctr] if partyid3==2, col;

/* Table A16 */

tab iraqwin bushappr [iweight=wtfctr] if partyid3==1, col;
tab disapptime bushappr [iweight=wtfctr] if partyid3==1, col;

/* Table A17 */

tab iraqwin bushappr [iweight=wtfctr] if partyid3==0, col;
tab disapptime bushappr [iweight=wtfctr] if partyid3==0, col;

/* Table A18 */

ologit iraqwin bushappr dem rep ideology [pweight=wtfctr]; 
ologit iraqwin bushappr dem rep ideology female age black hispanic
income [pweight=wtfctr];

/* Table A19 */

ologit disapptime bushappr dem rep ideology [pweight=wtfctr]; 
ologit disapptime bushappr dem rep ideology female age black hispanic
income [pweight=wtfctr];

log close;

/* outsheet wtfctr d1 d2 d4 d5a d5b d5c d5d d9 d9a d10 d14 q2 q19 q20 q24
q26 using gallup.csv, comma replace; */

